<body>

<table id="test1_dg">


</table>
<script type="text/javascript">
    $(function () {
        var test1_menu =
                [
                    [   {field: "name", title: "name", width: 100},
                        {field: "id", title: "id", width: 100, hidden: true},
                        {field: "description", title: "description", width: 100},
                        {field: "iconcls", title: "iconcls", width: 100},
                        {field: "iconscls", title: "iconscls", width: 100},

                        {field: "seq", title: "seq", width: 100},
                        {field: "url", title: "url", width: 100},
                        {field: "pid", title: "pid", width: 100}


                    ]
                ]

        $('#test1_dg').datagrid({
            url: '${pageContext.request.contextPath}' + '/initleft/grid.do',
            fit: true,
            fitColumns: true,
            pagination: true,
            columns: test1_menu,
            rownumbers: true,
            toolbar: '#test1_toolbar',
            singleSelect: true

        });
    })
</script>

<div id="test1_toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="add()">增加</a>
    <a href="#" class="easyui-linkbutton"
       iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="del()">删除</a> &nbsp;<INPUT type="text" id="conditiontxt"
                                           value="">
    <a href="#" class="easyui-linkbutton"
       iconCls="icon-search" plain="true" onclick="searchForm()">查询</a>
</div>

<!-- dialog -->
<div id="test1_dlg" class="easyui-dialog"
     style="width:400px;height:350px;padding:10px 20px" closed="true"
     buttons="#dlg-buttons">
    <div class="ftitle">auth_menu</div>
    <form id="test1_fm" method="post">
        <div class="fitem" hidden="true"><label>ID</label><input name="id"></div>
        <div class="fitem"><label>DESCRIPTION</label><input name="description"></div>
        <div class="fitem"><label>ICONCLS</label><input name="iconcls"></div>
        <div class="fitem"><label>ICONSCLS</label><input name="iconscls"></div>
        <div class="fitem"><label>NAME</label><input name="name"></div>
        <div class="fitem"><label>SEQ</label><input name="seq"></div>
        <div class="fitem"><label>URL</label><input name="url"></div>
        <div class="fitem"><label>PID</label><input name="pid"></div>


    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="save()">保存</a> <a href="#" class="easyui-linkbutton"
                                  iconCls="icon-cancel" onclick="$('#test1_dlg').dialog('close')">取消</a>
</div>
<!-- dialog end-->

<script type="text/javascript">
    var test1_url
    function add() {
        $('#test1_dlg').dialog('open').dialog('setTitle', 'auth_menu');
        $('#test1_fm').form('clear');
        url = '${pageContext.request.contextPath}' + '/initleft/savemenu.do';
    }
    function edit() {
        var row = $('#test1_dg').datagrid('getSelected');
        if (row) {
            $('#test1_dlg').dialog('open').dialog('setTitle', '更新');
            $('#test1_fm').form('load', row);
            url = '${pageContext.request.contextPath}' + '/initleft/editmenu.do'
        }
    }
    function save() {
        $('#test1_fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                var result = jQuery.parseJSON(result)

                if (result.errorMsg) {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#test1_dlg').dialog('close'); // close the dialog
                    $('#test1_dg').datagrid('reload'); // reload the user data
                }
            }
        });
    }
    function del() {
        var row = $('#test1_dg').datagrid('getSelected');
        if (row) {
            $.messager
                    .confirm(
                    '删除',
                    '确定删除当前记录吗？',
                    function(r) {
                        if (r) {
                            $
                                    .post(
                                            '${pageContext.request.contextPath}' + '/initleft/deletemenu.do',
                                    {
                                        id : row.id
                                    },
                                    function(result) {
                                        if (result.success) {
                                            $('#test1_dg').datagrid(
                                                    'reload'); // reload the user data
                                        } else {
                                            $.messager
                                                    .show({ // show error message
                                                        title : 'Error',
                                                        msg : result.errorMsg
                                                    });
                                        }
                                    }, 'json');
                        }
                    });
        }
    }
</script>
</body>